package com.lwx.chapter7;

/**
 * 求联通分量个数
 */
public class Component {
    private Gragh gragh;
    private boolean[] visited;
    /**
     * 联通分量个数
     */
    int ccount;
    public Component(Gragh gragh){
        visited = new boolean[gragh.V()];
        ccount = 0;
        for (int i = 0; i < gragh.V(); i++) {
            visited[i] = false;
        }
    }

    public void dfs(int v){
        visited[v] = true;
        Gragh.adjIterator adjIterator = gragh.new adjIterator(gragh, v);
        for (int i = adjIterator.begin(); !adjIterator.end() ; i = adjIterator.next()) {
            if(!visited[i]){
                dfs(i);
            }
        }

    }
}
